/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.ce.commands.systemacc;

import com.bionic.ce.businesslogic.SystemAccService;
import com.bionic.ce.commands.ICommand;
import com.bionic.ce.manager.Config;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author MAXIM
 */
public class CommandAddNewSystemAcc implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null;
        String currency = request.getParameter("currency");
        Integer userId = Integer.parseInt(request.getParameter("userId"));
        boolean b=SystemAccService.returnCurrentSystemAccountsInfo(userId, currency).isEmpty();
        if(b){SystemAccService.createNewSystemacc(currency,userId);
        (new CommandGoToSystemAccountInfo()).execute(request, response);
        page = Config.getInstance().getProperty(Config.GOTOSYSTEMACCAOUNTSINFO);}
        else{
            request.setAttribute("systemaccadderror", "You can`t have more than one acount in "+currency);
            page = Config.getInstance().getProperty(Config.GOTOADDNEWSYSTEMACC);
        }
        return page;
    }
}